import urllib.request
from threading import Thread
from time import sleep
import requests
import os

def ip_gen():
    while True:
        a = str(list(os.urandom(1)))
        b = str(list(os.urandom(1)))
        c = str(list(os.urandom(1)))
        d = str(list(os.urandom(1)))
        ip = (str(a[1:-1]) + '.' + str(b[1:-1]) + '.' + str(c[1:-1]) + '.' + str(d[1:-1]))
        print(ip)
        
        try:
            print(urllib.request.urlopen('http://' + ip, timeout = 3).getcode())
            f = open('ip.txt', 'a')
            f.write(ip+"\n")
            f.close()
        except:
            pass
        sleep(0.5)

th1 = Thread(target=ip_gen)
th2 = Thread(target=ip_gen)
th3 = Thread(target=ip_gen)
th4 = Thread(target=ip_gen)

def start():
    th1.start()
    th2.start()
    th3.start()
    th4.start()
    
def stop():
    th1.stop()
    th2.stop()
    th3.stop()
    th4.stop()
    
